
const app =getApp()
Page({
  data: {
    orderState: 2,
    pageNum:1,
    pageTotal:0,
    show:false,
    order_list:[]
  },
  onLoad: function (options) {
    this.setData({
      orderState: Number(options.state)
    })
    this.getOrderList()
  },
  onReachBottom() {
    if(this.data.pageNum<this.data.pageTotal){
      this.setData({
        pageNum: this.data.pageNum + 1
      })
      wx.showLoading({
        title: '加载更多...',
        icon: 'loading'
      })
      this.getOrderList()
    }
  },
  getOrderList(){
    let _this = this
    app.util.request({
      // url: 'api/orders/findApi',
      url: 'api/award/findLimit',
      method: "post",
      data: {
        state: _this.data.orderState,
        page:_this.data.pageNum,
        pageSize:10,
      },
      success(response) {
        wx.hideLoading()
        if (response.data.code == 0) {
          _this.setData({
            pageTotal:response.data.data.pages,
            order_list:[..._this.data.order_list,...response.data.data.list]
          })
        }
      }
    })
  },
  toRefund(e){
    let _this = this
    app.util.request({
      url: 'api/orders/appRefund',
      method: "post",
      data: {
        id:e.currentTarget.dataset.id,
      },
      success(response) {
        if (response.data.code == 0) {
          wx.showToast({
            title: '退款成功'
          })
          this.getOrderList()
        }
      }
    })
  }
})
